import { useEffect } from "react";
import { useState } from "react"

export default function Reducer() {
    const [temp, setTemp] = useState(20)
    const [suggest, setSuggest] = useState('长袖');
    // 不可以这样写，await 后面要接promise对象
    // async function add() {
    //     await setTemp(temp + 1)
    //     suggestClothes()
    // }
    // 可以这样写
    function add() {
        setTemp(temp + 1)
    }
    function sub() {
        setTemp(temp - 1)
    }
    useEffect(() => {
        if (temp > 25) {
            setSuggest('短袖')
        } else {
            setSuggest('长袖')
        }
    }, [temp])
    return (
        <div>
            <button onClick={add}>+</button>
            <button onClick={sub}>-</button>
            <div>{temp}</div>
            <div>建议穿衣{suggest}</div>
        </div>
    )
}
